<template>
  <DatasetList
      paginationPosition="left"
      :searchForm="searchForm"
      :fastForm="fastForm"
      :permission="permission"
      :collapse.sync="collapse"
      :fastProps="fastProps"
      :formatRow="formatResoureList"
      :filterProps="{
        readyNumAuth: false,
        receivedNumAuth: false,
        readNumAuth: false,
        comWidgetTypeShow: false,
        modelNumAuth: false,
        lastSyncDateAuth: false
      }"
      :rowKey="(isAssetsModel&&isAssetsModel())?'resourceId':'id'"
      :disabledRowFormat="disabledRowFormat"
      ref="dashboard"
      pagination-position="right"
      model="selection"
      :device="device"
      @event:addSelected="onAdd"
      :selectionRows="currentSelectionRows"
  >
    <!-- <template v-slot:footer-action>
      <el-button type="primary" size="mini" @click.stop="onAdd"
      >Add Selected</el-button
      >
    </template> -->
  </DatasetList>
</template>

<script>
import DatasetList from '@/views/modules/mspbots/dataset/list-dataset.vue'
import { merge, cloneDeep } from 'lodash'
import { PAGE_SETTING } from '@/components/storybook/settings/page'

export default {
  inject: {isAssetsModel: {default: false}},
  name: 'DatasetTabpane',
  components: {
    DatasetList
  },
  props: {
    defaultSelectionRows: {
      type: Array,
      default: () => []
    },
    rootBusinessType: {
      type: Array,
      default: () => []
    },
    device: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      collapse: false,
      searchForm: {
        name: '',
        resourceType: 1,
        type: 1,
        internal: false,
        reuse: true,
        orderField: '',
        order: [{ sort: 'DESC', field: 'update_date' }],
        filter: {
          type: ['Custom']
        },
        integration: {
          showAllIntegration: false,
          integrationGroup: []
        },
        pagination: merge(cloneDeep(PAGE_SETTING), {
          total: 0
        })
      },
      fastForm: {
        businessType: ['Custom'],
        type: 'scorecard-report'
      },
      fastProps: {
        action: false,
        stickyFormat(item) {
          return !item.id
        },
        format(item) {
          if (item.name === 'FAVORITE') {
            return 'My Favorites'
          }
          if (item.name === 'CUSTOM') {
            return 'My Dashboard'
          }
          if (item.name === 'TEMPLATE') {
            return 'Template Dashboard'
          }
          return item.name
        }
      },
      permission: {
        sharedAuth: false,
        lastSyncDateAuth: false,
        moreMenuAuth: false,
        collectAuth: false,
        fastAuth: false
      }
    }
  },
  computed: {
    currentSelectionRows() {
      return cloneDeep(this.defaultSelectionRows)
    }
  },
  methods: {
    formatResoureList(item) {
      if (item.type === 100101) {
        item.createName = item.companyName
        item.businessTypeName = 'Community'
      } else {
        item.createName = item.creatorName
        item.businessTypeName =
            item.businessType === 'MSPbots Internal'
                ? 'Internal'
                : item.businessType
      }
      return item
    },
    disabledRowFormat(item) {
      return !this.rootBusinessType.includes(item.businessType)
    },

    onAdd(rows) {
      this.$emit('event:addSelected', rows)
    }
  }
}
</script>

